package edu.udlap.spring2008.is300.finalexam.app.mvc.view;

import edu.udlap.spring2008.is300.finalexam.framework.mvc.controller.Controller;
import edu.udlap.spring2008.is300.finalexam.framework.mvc.view.ViewComponent;
import edu.udlap.spring2008.is300.finalexam.framework.mvc.view.ViewRootCompositeComponent;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

/**
 *
 * @author Ruslán Ledesma Garza
 */
public class ViewWindow extends ViewRootCompositeComponent
{
    protected JFrame frame = new JFrame();

    public ViewWindow(
            String title,
            Controller controller,
            Dimension size)
    {
        this(title, controller);
        frame.setSize(size);
    }
    
    public ViewWindow(String title, Controller controller)
    {
        this(controller);
        frame.setTitle(title);
    }
    
    public ViewWindow(Controller controller)
    {
        super(controller);        
        frame.setBounds(0, 0, 300, 300);
        frame.setLocationByPlatform(true);
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.setVisible(true);
    }

    // <editor-fold desc="overriden & implemented operations...">
    @Override
    public void addChild(ViewComponent child)
    {
        super.addChild(child);
        
        ///add the actual component to the content pane...
        frame.getContentPane().add(child.getComponent());
        //frame.getContentPane().validate();
        //frame.getContentPane().repaint();
        frame.validate();
        frame.repaint();
        //frame.pack();
    }

    @Override
    public void removeChild(ViewComponent child)
    {
        super.removeChild(child);
        
        ///remove the actual component from the content pane...
        frame.getContentPane().remove(child.getComponent());
        //frame.getContentPane().validate();
        //frame.getContentPane().repaint();
        frame.validate();
        frame.repaint();
        //frame.pack();
    }
    
    public Component getComponent()
    {
        return (Component)frame;
    }
    // </editor-fold>
    
}
